/**
 * Copyright (c) 2010-2020 by skzr.org
 * All rights reserved.
 * @Author <a href="mailto:skzr.org@gmail.com">skzr.org</a>
 * @date 2011-3-17 下午10:58:29
 */
package org.skzr.logging.util.impl;

import java.io.IOException;
import java.io.InputStream;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

import org.skzr.logging.util.IResource;

/**
 * @author <a href="mailto:skzr.org@gmail.com">skzr.org</a>
 * @version 1.0.0
 * @since JDK1.6
 */
public class ResourceJarEntry implements IResource {
	private final transient String fileName;
	private final transient JarFile jarFile;
	private final transient JarEntry jarEntry;
	
	public ResourceJarEntry(JarFile jarFile, String rootEntryPath, JarEntry jarEntry) {
		this.jarFile = jarFile;
		this.fileName = jarEntry.getName().substring(rootEntryPath.length());
		this.jarEntry = jarEntry;
	}
	
	@Override
	public String toString() {
		return getClass().getSimpleName() + "@" + Integer.toHexString(hashCode()) + " jar:" + jarEntry;
	}

	@Override
	public String getFileName() {
		return fileName;
	}

	@Override
	public InputStream getInputStream() throws IOException {
		return jarFile.getInputStream(jarEntry);
	}
}
